<div class="row animate fadeIn">
    <form id="item_form" class="form-horizontal">
                <div class="ibox-title" style="border:none;"><h5 style="color: #00afef"><i>Item Add</i></h5>
                    <div class="ibox-tools">    
                         <button class="btn btn-primary btn-sm save-btn-tab" id="submit-uom">Save</button>
                         <a id="cancel_add" class="btn btn-sm btn-outline btn-info cancel-btn-tab">Cancel</a>
                    </div>
                </div>
                <div class="ibox-content">
                    <form class="form-horizontal">
                        <div class="form-group">
                            <label class="col-lg-2 control-label">Business Unit</label>
                            <div class="col-lg-4">
                                <input readonly type="text" style="width: 189px;" value="<?php echo $this->session->userdata('bu_name'); ?>" class="form-control" name="bu">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-lg-2 control-label">Item Number</label>
                            <div class="col-lg-4">
                                <input type="text" style="width: 189px;" class="form-control" name="item_number">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-lg-2 control-label">Description</label>
                            <div class="col-lg-2">
                                <input type="text" style="width: 159px;" class="form-control" name="item_description">
                            </div>
                        </div>
                        <div class="form-group"><label class="col-sm-2 control-label">Base UOM</label>
                            <div class="col-sm-2">
                                <select style="width: 159px;" class="chosen-select" name="item_uom">
                                    <?php foreach ($uom as $uom_data) { ?>
                                        <option value="<?php echo $uom_data->uom_code; ?>"><?php echo $uom_data->uom_code; ?></option>
                                    <?php } ?>
                                </select>
                            </div>
                        </div>
                        <div class="form-group"><label class="col-sm-2 control-label">Item Type</label>
                            <div class="col-sm-4">
                                    <select style="width: 189px;" class="chosen-select" name="item_type">
                                        <option value=""> </option>
                                        <?php foreach ($type as $inv_types) { ?>
                                            <option value="<?php echo $inv_types->item_type; ?>"><?php echo $inv_types->meaning; ?></option>
                                        <?php } ?>
                                    </select>
                            </div>
                        </div>
                        <div class="form-inline form-group" >
                            <div><label class="col-sm-2 control-label">Item Group</label>
                                <div class="col-lg-4">
                                    <select style="width: 189px;" class="chosen-select" name="item_group">
                                        <option value=""> </option>
                                        <?php foreach ($groups as $inv_groups) { ?>
                                            <option value="<?php echo $inv_groups->item_group; ?>"><?php echo $inv_groups->meaning; ?></option>
                                        <?php } ?>
                                    </select>
                                </div>
                            </div>
                            <div><label class="col-sm-2 control-label">Status</label>
                                
                            </div><div class="col-sm-2">
                                    <select class="form-control m-b" id="pType2" name="item_status">
                                        <option value="A">Active</option>
                                        <option value="O">Obsolete</option>
                                    </select>
                                </div>
                        </div>
                        <div class="form-group">
                            <label class="col-lg-2 control-label">COGS Acct</label>
                            <div class="col-lg-4">
                                    <select style="width: 189px;" class="chosen-select" name="cogs_acct">
                                        <option value="">Select</option>
                                        <?php foreach ($cogs as $cogs_acct) { ?>
                                            <option value="<?php echo $cogs_acct->account_id; ?>"><?php echo $cogs_acct->acct_name; ?> (<?php echo $cogs_acct->acct_code; ?>)</option>
                                        <?php } ?>
                                    </select>
                                </div>
                        </div>
                        <div class="form-group">
                            <label class="col-lg-2 control-label">Expense Acct</label>
                            <div class="col-lg-4">
                                    <select style="width: 189px;" class="chosen-select" name="exp_acct">
                                        <option value="">Select</option>
                                        <?php foreach ($expense as $exp_acct) { ?>
                                            <option value="<?php echo $exp_acct->account_id; ?>"><?php echo $exp_acct->acct_name; ?> (<?php echo $exp_acct->acct_code; ?>)</option>
                                        <?php } ?>
                                    </select>
                                </div>
                        </div>
                        <div class="form-group">
                            <label class="col-lg-2 control-label">Sales Acct</label>
                            <div class="col-lg-4">
                                    <select style="width: 189px;" class="chosen-select" name="sales_acct">
                                        <option value="">Select</option>
                                        <?php foreach ($sales as $sl_acct) { ?>
                                            <option value="<?php echo $sl_acct->account_id; ?>"><?php echo $sl_acct->acct_name; ?> (<?php echo $sl_acct->acct_code; ?>)</option>
                                        <?php } ?>
                                    </select>
                                </div>
                        </div>
                        <div class="form-group">
                            <label class="col-lg-2 control-label">Unit Selling Price</label>
                            <div class="col-lg-3">
                                <div class="input-group m-b"><span class="input-group-addon">P</span> <input name="unit_selling_price" type="text" class="form-control text-right"></div>
                            </div>
                        </div>
                        <div class="form-inline form-group" >
                            <div><label class="col-lg-2 control-label">Inventory</label>
                                <div class="col-lg-1">
                                    <input type="checkbox" value="ok" class="i-checks" name="inv" checked>
                                </div>
                            </div>
                            <div><label class="col-lg-2 control-label">Purchasing</label>
                                <div class="col-lg-1">
                                    <input type="checkbox" value="ok" class="i-checks" name="pur" checked>
                                </div>
                            </div>
                        </div>
                        <div class="form-inline form-group" >
                            <div><label class="col-lg-2 control-label">Set</label>
                                <div class="col-lg-1">
                                    <input type="checkbox" value="ok" class="i-checks" name="set">
                                </div>
                            </div>
                            <div><label class="col-lg-2 control-label">Costing</label>
                                <div class="col-lg-1">
                                    <input type="checkbox" value="ok" class="i-checks" name="cos" checked>
                                </div>
                            </div>
                        </div>
                        <div class="form-inline form-group" >
                             <div><label class="col-lg-2 control-label">Sell</label>
                                <div class="col-lg-1">
                                    <input type="checkbox" value="ok" class="i-checks" name="sel" checked>
                                </div>
                            </div>
                            <div><label class="col-lg-2 control-label">Enabled</label>
                                <div class="col-lg-1">
                                    <input type="checkbox" value="ok" class="i-checks" name="ena" checked>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
<script>
    $(document).ready(function(){
        $('#item_form').data('serialize',$('#item_form').serialize());
        $('.i-checks').iCheck({
                    checkboxClass: 'icheckbox_square-green',
                    radioClass: 'iradio_square-green',
              });
        $("#item_form").validate({
                 rules: {
                     bu: {
                         required: true
                     },
                     item_number: {
                         required: true
                     },
                     item_description: {
                         required: true,
                         lettersonly: true
                     }
                 },
                 submitHandler: function(form){
                    $.ajax({
                        type: "POST",
                        url: "<?php echo base_url($this->session->userdata('forajax').'/insert_item'); ?>",
                        data: $('#item_form').serialize(),
                        dataType: 'json',
                        success: function(data){
                           if(data[0].error != 1){
                                notifymsg("success",". . .Inventory Item Added Successfully");
                                close_add(); active_search();
                           }else{
                            notifyClass("error",data[0].msg);
                           }
                        },
                        complete: function() {

                        },
                        beforeSend: function(){
                           
                        }
                    });
                 }
        }); 
        function alert_cancel(){
            if($('#item_form').serialize()!=$('#item_form').data('serialize')){
                // Form has changed!!!
                swal({
                                          title: "Are you sure?",
                                          text: "Your work will not be save",
                                          type: "warning",
                                          showCancelButton: true,
                                          confirmButtonColor: "#DD6B55",
                                          confirmButtonText: "Leave",
                                          cancelButtonText: "Stay",
                                          closeOnConfirm: true,
                                          closeOnCancel: true },
                                      function (isConfirm) {
                                          if (isConfirm) {
                                            swal("success");
                                              close_add(); active_search();
                                              notifyClass("clear","");
                                          } else {
                                              swal("Cancelled");
                                          }
                                      });
                }else{
                close_add(); active_search();
                notifymsg("hide","hide");
            }
        }
        $('#cancel_add').click(function(){
            alert_cancel();
           }); 
        $(".chosen-select").chosen({width:"95%;"});     
        $('#addX').click(function(){
            alert_cancel();       
       });
    });
</script>